package puzzle.core.tiles;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import puzzle.core.Direction;
import puzzle.core.Directional;
import puzzle.core.Tile;
import puzzle.core.TileType;
import puzzle.core.tiles.ImageTile;

public class DirectionalImageTile extends ImageTile implements Directional {
  
  protected Direction dir;
  
  public DirectionalImageTile(TileType t, Direction d, Image i, Color c) {
    super(t, i, c);
    this.dir = d;
    if (dir==null||dir==Direction.NONE) {
      throw new IllegalArgumentException("Directional defined with no direction.");
    }
  }
  
  public DirectionalImageTile(TileType t, Direction d, Image i) {
    this(t, d, i, null);
  }
  
  public Direction getDirection() {
    return dir;
  }
  
  public void render(Graphics g, int x, int y) {
    g.rotate(x+Tile.WIDTH/2.0f, y+Tile.HEIGHT/2.0f, dir.getAngle());
    super.render(g, x, y);
    g.rotate(x+Tile.WIDTH/2.0f, y+Tile.HEIGHT/2.0f, -dir.getAngle());
  }
}
